/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aptech.DAO;

import com.aptech.model.RealEstateStyle;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

/**
 *
 * @author Hoang Quy Hong An
 */
public class realEstateStyleDAO {

    private  Connection myCon;
    private  PreparedStatement ps;
    private  ResultSet rs;
    private  String strCommand = "";

     public  ArrayList<RealEstateStyle> getAllRealEstateStyle(){
        ArrayList<RealEstateStyle> listRealEstateStyle = new ArrayList<RealEstateStyle>();
        RealEstateStyle res = null;
        strCommand = "SELECT realEstateStyleID ,realEstateStyleName "+
                        "FROM tbl_RealEstateStyle WHERE realEstateStyleStatus = 1";
        try{
            myCon = myConnection.getConnection();
            ps = myCon.prepareStatement(strCommand, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
            rs = ps.executeQuery();
            while (rs.next()) {
                res = new RealEstateStyle(rs.getInt("realEstateStyleID"), rs.getString("realEstateStyleName"));
                listRealEstateStyle.add(res);
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally{
            myConnection.closeConnection(myCon, ps, rs);
        }
        return listRealEstateStyle;
     }

     public String getRealEstateStyleByID(int realEstateStyleID){
         String realEstateStyleName = "";
        strCommand = "SELECT realEstateStyleName "+
                        "FROM tbl_RealEstateStyle WHERE realEstateStyleID = ?";
        try{
            myCon = myConnection.getConnection();
            ps = myCon.prepareStatement(strCommand, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
            ps.setInt(1, realEstateStyleID);
            rs = ps.executeQuery();
            while (rs.next()) {
              realEstateStyleName = rs.getString("realEstateStyleName");
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally{
            myConnection.closeConnection(myCon, ps, rs);
        }
        return realEstateStyleName;
     }

}
